package algorithm_demo.demo04;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * 日期之间隔几天
 * https://leetcode.cn/problems/number-of-days-between-two-dates/solution/ri-qi-zhi-jian-ge-ji-tian-by-leetcode-solution/
 *
 * @author Api
 * @date 2023/2/15 22:13
 */
public class Code03_Solution {
    public int daysBetweenDates(String date1, String date2) {
        LocalDate d1 = LocalDate.parse(date1, DateTimeFormatter.ofPattern("yyy-MM-dd"));
        LocalDate d2 = LocalDate.parse(date2, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        int result = (int) (d2.toEpochDay() - d1.toEpochDay());
        return Math.abs(result);
    }

}
